using Godot;

public partial class TestPlayer : CharacterBody2D
{
    [Export]
    public float Speed = 200.0f;
    
    private Label positionLabel;
    
    public override void _Ready()
    {
        // 创建位置显示标签
        CreatePositionLabel();
    }
    
    private void CreatePositionLabel()
    {
        // 创建一个CanvasLayer来显示UI
        var canvasLayer = new CanvasLayer();
        AddChild(canvasLayer);
        
        // 创建位置标签
        positionLabel = new Label();
        positionLabel.Text = $"位置: {Position}";
        positionLabel.Position = new Vector2(10, 10);
        canvasLayer.AddChild(positionLabel);
    }
    
    public override void _Process(double delta)
    {
        Vector2 velocity = Vector2.Zero;
        
        // 简单的键盘输入检测
        if (Input.IsKeyPressed(Key.A) || Input.IsKeyPressed(Key.Left))
        {
            velocity.X = -Speed;
        }
        else if (Input.IsKeyPressed(Key.D) || Input.IsKeyPressed(Key.Right))
        {
            velocity.X = Speed;
        }
        
        if (Input.IsKeyPressed(Key.W) || Input.IsKeyPressed(Key.Up))
        {
            velocity.Y = -Speed;
        }
        else if (Input.IsKeyPressed(Key.S) || Input.IsKeyPressed(Key.Down))
        {
            velocity.Y = Speed;
        }
        
        // 直接设置位置而不是使用物理系统
        Position += velocity * (float)delta;
        
        // 更新位置显示
        if (positionLabel != null)
        {
            positionLabel.Text = $"位置: {Position:F1}";
        }
        
        // 限制玩家在屏幕范围内
        Position = new Vector2(
            Mathf.Clamp(Position.X, -600, 600),
            Mathf.Clamp(Position.Y, -300, 300)
        );
    }
} 